/**
 * 
 * 深圳市店联电子商务有限公司
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.component;

import java.awt.FlowLayout;

import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import com.ruipengkj.commons.util.Util;
/**
 * 说明：
 * 文本+输入框
 * @Author： 刘国华
 * @Date：2012-07-24
 */
public class JLabelJRadioGroupButtonComponent extends JPanel{
	
	private static final long serialVersionUID = 1L;

	private JRadioButton[] optionButtons;
	

	public int getSelectIndex()
	{
		for(int i = 0; i < optionButtons.length; i ++)
		{
			if(optionButtons[i].isSelected())
			{
				return i;
			}
		}
		
		return -1;
	}
	
	public String getSelectOptionText()
	{
		int r = getSelectIndex();
		if(r >= 0)
		{
			return optionButtons[r].getText();
		}
		else
		{
			return null;
		}
	}
	
	public JRadioButton getSelectOption()
	{
		int r = getSelectIndex();
		if(r >= 0)
		{
			return optionButtons[r];
		}
		else
		{
			return null;
		}
	}
	
	//private Dimension dimension=null;
	public JLabelJRadioGroupButtonComponent(String lable, String[] _options, int width){
		this.setLayout(Util.FlowLayout(FlowLayout.LEFT));
		//dimension=new Dimension(width, 25);
		JLabel label=new JLabel(lable);
		//单选按钮分组以保证单一选择
		ButtonGroup group = new ButtonGroup();

		this.add(label);
		optionButtons = new JRadioButton[_options.length];
		for(int i = 0; i < _options.length; i ++)
		{
			optionButtons[i] = new JRadioButton(_options[i], i == 0);
			this.add(optionButtons[i]);
			group.add(optionButtons[i]);
		}
	}


}
